* * * TOP INCOME SHARES IN SWITZERLAND * * * 
 
 * Isabel Martinez, University of St. Gallen, 2012
 
 /**** 
 NOTE:
 1) estimation of top wealth shares 2003-2011
 2)
 ***/
 
 
 *_____________________________________________________________________________________
 
version 14.0

clear all
set more off
cap log close
cap graph drop _all
cap clear matrix 


// read-in total adult population and married adults
	import excel "$thepath/Population.xlsx", sheet("popstat_annual") cellrange(L1:P32) clear firstrow
	gen total_taxunits = total_taxunits_annual 
	gen total_adults = total_adults_annual 
	gen cant=0
	keep year total_taxunits total_adults cant
	tempfile popstat2
	save "`popstat2'"

use  "$thepath/6a_Swiss_wealth_data_2003-2011.dta", clear
merge m:1 cant year using  "`popstat2'"
drop if _merge==2
drop _merge



cd "$thepath/results"

 
program define make_wealth_variables
  
*1) Generate total wealth we_s above each threshold s

 gen we_10000 = (w_10000)
 label var we_10000 "Total wealth of all tax units with wealth above 10 million SFr."
 
 gen we_5000 = (w_5000 + we_10000)
 label var we_5000 "Total wealth of all tax units with wealth above 5 million SFr."
 
 gen we_3000 = (w_3000 + we_5000)
 label var we_3000 "Total wealth of all tax units with wealth above 3 millionSFr."
 
 gen we_2000 = (w_2000 + we_3000)
 label var we_2000 "Total wealth of all tax units with wealth above 2 million SFr."
 
 gen we_1000 = (w_1000 + we_2000)
 label var we_1000 "Total wealth of all tax units with wealth above 1 million SFr."
 
 gen we_500 = (w_500 + we_1000)
 label var we_500 "Total wealth of all tax units with wealth above 500'000 SFr."
 
 gen we_200 = (w_200 + we_500)
 label var we_200 "Total wealth of all tax units with wealth above 200'000 SFr."

 gen we_100 = (w_100 + we_200)
 label var we_100 "Total wealth of all tax units with wealth above 100'000 SFr."
 
 gen we_50 = (w_50 + we_100)
 label var we_50 "Total wealth of all tax units with wealth above 50'000 SFr."
 
 gen we_0=(w_0 + we_50)
 label var we_0 "Total wealth of all tax units with wealth above 0 SFr."
 
 *** express wealth in francs rather than in millions
 foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
  replace we_`s' = we_`s'*1000000
 }
 replace w_total=w_total*1000000
  
  *2) Generate total number of tax units t_s above each threshold s:
  
   gen t_10000 = (tu_10000)
 label var t_10000 "Number of tax units with wealth above 10 million SFr."
 
 gen t_5000 = (tu_5000 + t_10000)
 label var t_5000 "Number of tax units with wealth above 5 million SFr."
 
 gen t_3000 = (tu_3000 + t_5000)
 label var t_3000 "Number of tax units with wealth above 3 millionSFr."
 
 gen t_2000 = (tu_2000 + t_3000)
 label var t_2000 "Number of tax units with wealth above 2 million SFr."
 
 gen t_1000 = (tu_1000 + t_2000)
 label var t_1000 "Number of tax units with wealth above 1 million SFr."
 
 gen t_500 = (tu_500 + t_1000)
 label var t_500 "Number of tax units with wealth above 500'000 SFr."
 
 gen t_200 = (tu_200 + t_500)
 label var t_200 "Number of tax units with wealth above 200'000 SFr."

 gen t_100 = (tu_100 + t_200)
 label var t_100 "Number of tax units with wealth above 100'000 SFr."
 
 gen t_50 = (tu_50 + t_100)
 label var t_50 "Number of tax units with wealth above 50'000 SFr."
 
 gen t_0=(tu_0 + t_50)
 label var t_0 "Number of tax units with wealth above 0 SFr."
 
 
  
 * 3) Generate the average wealth w_s above each threshold s: 
  
  foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
  gen avg_`s'=we_`s'/t_`s'
  label var avg_`s' "Average wealth of all tax uints with wealth above `s''000 SFr."
  }
  

 * 4) Calculate the cumulated population shares p_s above each threshold s:
 foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen p_`s'=t_`s'/total_taxunits
label var p_`s' "Share of tax units with wealth above `s''000 SFr."
}
 
 
 * 5) Calculate the local paretian distribution parameters b_s, a_s, k_s for each threshold s:
 
 foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
 * 5.1) calculate b
 gen b_`s'= avg_`s'/(`s'*1000)
 label var b_`s' "Local beta parameter for wealth > `s''000 SFr."
 
 ** 5.2) calculate a
 gen a_`s' = b_`s'/(b_`s'-1)
 label var a_`s' "Local alpha parameter for wealth > `s''000 SFr."
 
 *** 5.3) calculate k
 gen k_`s' = `s'*1000*p_`s'^(1/a_`s')
 label var k_`s' "Local k parameter for wealth > `s''000 SFr."
 }
 
  end
  
  
  quietly make_wealth_variables
  

 
*    ** top 10% **    *
   
* create the absolute deviation from the 10%-population share for each wealth bracket _`s'
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen abs90_`s'= abs(p_`s'- 0.1)
}
 
* create an indicator (dummy) indicating the bracket where p_`s' is closest to 10% 
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen bracket90_`s'=min(abs90_50, abs90_100, abs90_200, abs90_500, abs90_1000, abs90_2000, abs90_3000, abs90_5000, abs90_10000)
replace bracket90_`s' = 0 if bracket90_`s' !=abs90_`s'
replace bracket90_`s' = 1 if bracket90_`s'==abs90_`s'
}

*drop the top10% absolute deviation variables
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
drop abs90_`s'
}

*calculate the top10% wealth threshold ts90:
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen ts90_`s' = (k_`s'/0.1^(1/a_`s'))*bracket90_`s'
replace  ts90_`s' = 0 if ts90_`s'==.
}
gen ts90 =  ts90_50+ ts90_100+ ts90_200+ ts90_500+ ts90_1000+ ts90_2000+ ts90_3000+ ts90_5000+ ts90_10000
label var ts90 "Net-Wealth threshold to belong to the top10%"

*calculate the average wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen we_avg90_`s' = ts90_`s'*b_`s'*bracket90_`s'
replace we_avg90_`s' = 0 if we_avg90_`s'==.
}
gen we_avg90 =we_avg90_50+ we_avg90_100+ we_avg90_200+ we_avg90_500+ we_avg90_1000+ we_avg90_2000+ we_avg90_3000+ we_avg90_5000+ we_avg90_10000
label var we_avg90 "Average net wealth of the top10% (i.e. above S90)"

*calculate the total wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen we_abv90_`s' = ts90_`s'*b_`s'*bracket90_`s'*0.1*total_taxunits
replace we_abv90_`s'=0 if we_abv90_`s'==.
}
gen we_abv90 =we_abv90_50+ we_abv90_100+ we_abv90_200+ we_abv90_500+ we_abv90_1000+ we_abv90_2000+ we_abv90_3000+ we_abv90_5000+ we_abv90_10000
label var we_abv90 "Total wealth of the top10% (i.e. above S90)"

*generate the beta coeffiecients for the top 10%
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen b90_`s' = b_`s'*bracket90_`s'
replace b90_`s'=0 if b90_`s'==.
}
gen b90 =b90_50+ b90_100+ b90_200+ b90_500+ b90_1000+ b90_2000+ b90_3000+ b90_5000+ b90_10000
label var b90 "beta-coefficient of the top10%"

* calculate the top10% wealth share
gen P90= we_abv90/w_total
label var P90 "Top 10% net wealth share on total net wealth"






   *    ** top 5% **    *
   
* create the absolute deviation from the 5%-population share for each wealth bracket _`s'
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen abs95_`s'= abs(p_`s'- 0.05)
}
 
* create an indicator (dummy) indicating the bracket where p_`s' is closest to 5% 
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen bracket95_`s'=min(abs95_50, abs95_100, abs95_200, abs95_500, abs95_1000, abs95_2000, abs95_3000, abs95_5000, abs95_10000)
replace bracket95_`s' = 0 if bracket95_`s' !=abs95_`s'
replace bracket95_`s' = 1 if bracket95_`s'==abs95_`s'
}

*drop the top5% absolute deviation variables
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
drop abs95_`s'
}

*calculate the top5% wealth threshold ts95:
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen ts95_`s' = (k_`s'/0.05^(1/a_`s'))*bracket95_`s'
replace  ts95_`s' = 0 if ts95_`s'==.
}
gen ts95 =  ts95_50+ ts95_100+ ts95_200+ ts95_500+ ts95_1000+ ts95_2000+ ts95_3000+ ts95_5000+ ts95_10000
label var ts95 "Net-Wealth threshold to belong to the top5%"

*calculate the average wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen we_avg95_`s' = ts95_`s'*b_`s'*bracket95_`s'
replace we_avg95_`s' = 0 if we_avg95_`s'==.
}
gen we_avg95 =we_avg95_50+ we_avg95_100+ we_avg95_200+ we_avg95_500+ we_avg95_1000+ we_avg95_2000+ we_avg95_3000+ we_avg95_5000+ we_avg95_10000
label var we_avg95 "Average net wealth of the top5% (i.e. above S95)"

*calculate the total wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen we_abv95_`s' = ts95_`s'*b_`s'*bracket95_`s'*0.05*total_taxunits
replace we_abv95_`s'=0 if we_abv95_`s'==.
}
gen we_abv95 =we_abv95_50+ we_abv95_100+ we_abv95_200+ we_abv95_500+ we_abv95_1000+ we_abv95_2000+ we_abv95_3000+ we_abv95_5000+ we_abv95_10000
label var we_abv95 "Total wealth of the top5% (i.e. above S95)"

*generate the beta coeffiecients for the top 5%
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen b95_`s' = b_`s'*bracket95_`s'
replace b95_`s'=0 if b95_`s'==.
}
gen b95 =b95_50+ b95_100+ b95_200+ b95_500+ b95_1000+ b95_2000+ b95_3000+ b95_5000+ b95_10000
label var b95 "beta-coefficient of the top5%"

* calculate the top5% wealth share
gen P95= we_abv95/w_total
label var P95 "Top 5% net wealth share on total net wealth"




*    ** top 1% **    *
   
* create the absolute deviation from the 1%-population share for each wealth bracket _`s'
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen abs99_`s'= abs(p_`s'- 0.01)
}
 
* create an indicator (dummy) indicating the bracket where p_`s' is closest to 1% 
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen bracket99_`s'=min(abs99_50, abs99_100, abs99_200, abs99_500, abs99_1000, abs99_2000, abs99_3000, abs99_5000, abs99_10000)
replace bracket99_`s' = 0 if bracket99_`s' !=abs99_`s'
replace bracket99_`s' = 1 if bracket99_`s'==abs99_`s'
}

*drop the top1% absolute deviation variables
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
drop abs99_`s'
}

*calculate the top1% wealth threshold ts99:
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen ts99_`s' = (k_`s'/0.01^(1/a_`s'))*bracket99_`s'
replace  ts99_`s' = 0 if ts99_`s'==.
}
gen ts99 =  ts99_50+ ts99_100+ ts99_200+ ts99_500+ ts99_1000+ ts99_2000+ ts99_3000+ ts99_5000+ ts99_10000
label var ts99 "Net-Wealth threshold to belong to the top1%"

*calculate the average wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen we_avg99_`s' = ts99_`s'*b_`s'*bracket99_`s'
replace we_avg99_`s' = 0 if we_avg99_`s'==.
}
gen we_avg99 =we_avg99_50+ we_avg99_100+ we_avg99_200+ we_avg99_500+ we_avg99_1000+ we_avg99_2000+ we_avg99_3000+ we_avg99_5000+ we_avg99_10000
label var we_avg99 "Average net wealth of the top1% (i.e. above S99)"

*calculate the total wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen we_abv99_`s' = ts99_`s'*b_`s'*bracket99_`s'*0.01*total_taxunits
replace we_abv99_`s'=0 if we_abv99_`s'==.
}
gen we_abv99 =we_abv99_50+ we_abv99_100+ we_abv99_200+ we_abv99_500+ we_abv99_1000+ we_abv99_2000+ we_abv99_3000+ we_abv99_5000+ we_abv99_10000
label var we_abv99 "Total wealth of the top1% (i.e. above S99)"

*generate the beta coeffiecients for the top 1%
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen b99_`s' = b_`s'*bracket99_`s'
replace b99_`s'=0 if b99_`s'==.
}
gen b99 =b99_50+ b99_100+ b99_200+ b99_500+ b99_1000+ b99_2000+ b99_3000+ b99_5000+ b99_10000
label var b99 "beta-coefficient of the top1%"

* calculate the top1% wealth share
gen P99= we_abv99/w_total
label var P99 "Top 1% net wealth share on total net wealth"





   *    ** top 0.5% **    *
   
* create the absolute deviation from the 0.5%-population share for each wealth bracket _`s'
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen abs995_`s'= abs(p_`s'- 0.005)
}
 
* create an indicator (dummy) indicating the bracket where p_`s' is closest to 0.5% 
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen bracket995_`s'=min(abs995_50, abs995_100, abs995_200, abs995_500, abs995_1000, abs995_2000, abs995_3000, abs995_5000, abs995_10000)
replace bracket995_`s' = 0 if bracket995_`s' !=abs995_`s'
replace bracket995_`s' = 1 if bracket995_`s'==abs995_`s'
}

*drop the top0.5% absolute deviation variables
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
drop abs995_`s'
}

*calculate the top0.5% wealth threshold ts995:
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen ts995_`s' = (k_`s'/0.005^(1/a_`s'))*bracket995_`s'
replace  ts995_`s' = 0 if ts995_`s'==.
}
gen ts995 =  ts995_50+ ts995_100+ ts995_200+ ts995_500+ ts995_1000+ ts995_2000+ ts995_3000+ ts995_5000+ ts995_10000
label var ts995 "Net-Wealth threshold to belong to the top0.5%"

*calculate the average wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen we_avg995_`s' = ts995_`s'*b_`s'*bracket995_`s'
replace we_avg995_`s' = 0 if we_avg995_`s'==.
}
gen we_avg995 =we_avg995_50+ we_avg995_100+ we_avg995_200+ we_avg995_500+ we_avg995_1000+ we_avg995_2000+ we_avg995_3000+ we_avg995_5000+ we_avg995_10000
label var we_avg995 "Average net wealth of the top0.5% (i.e. above S995)"

*calculate the total wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen we_abv995_`s' = ts995_`s'*b_`s'*bracket995_`s'*0.005*total_taxunits
replace we_abv995_`s'=0 if we_abv995_`s'==.
}
gen we_abv995 =we_abv995_50+ we_abv995_100+ we_abv995_200+ we_abv995_500+ we_abv995_1000+ we_abv995_2000+ we_abv995_3000+ we_abv995_5000+ we_abv995_10000
label var we_abv995 "Total wealth of the top0.5% (i.e. above S995)"

*generate the beta coeffiecients for the top 0.5%
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen b995_`s' = b_`s'*bracket995_`s'
replace b995_`s'=0 if b995_`s'==.
}
gen b995 =b995_50+ b995_100+ b995_200+ b995_500+ b995_1000+ b995_2000+ b995_3000+ b995_5000+ b995_10000
label var b995 "beta-coefficient of the top0.5%"

* calculate the top0.5% wealth share
gen P995= we_abv995/w_total
label var P995 "Top 0.5% net wealth share on total net wealth"





   *    ** top 0.1% **    *
   
* create the absolute deviation from the 0.1%-population share for each wealth bracket _`s'
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen abs999_`s'= abs(p_`s'- 0.001)
}
 
* create an indicator (dummy) indicating the bracket where p_`s' is closest to 0.1% 
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen bracket999_`s'=min(abs999_50, abs999_100, abs999_200, abs999_500, abs999_1000, abs999_2000, abs999_3000, abs999_5000, abs999_10000)
replace bracket999_`s' = 0 if bracket999_`s' !=abs999_`s'
replace bracket999_`s' = 1 if bracket999_`s'==abs999_`s'
}

*drop the top0.1% absolute deviation variables
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
drop abs999_`s'
}

*calculate the top0.1% wealth threshold ts999:
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen ts999_`s' = (k_`s'/0.001^(1/a_`s'))*bracket999_`s'
replace  ts999_`s' = 0 if ts999_`s'==.
}
gen ts999 =  ts999_50+ ts999_100+ ts999_200+ ts999_500+ ts999_1000+ ts999_2000+ ts999_3000+ ts999_5000+ ts999_10000
label var ts999 "Net-Wealth threshold to belong to the top0.1%"

*calculate the average wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen we_avg999_`s' = ts999_`s'*b_`s'*bracket999_`s'
replace we_avg999_`s' = 0 if we_avg999_`s'==.
}
gen we_avg999 =we_avg999_50+ we_avg999_100+ we_avg999_200+ we_avg999_500+ we_avg999_1000+ we_avg999_2000+ we_avg999_3000+ we_avg999_5000+ we_avg999_10000
label var we_avg999 "Average net wealth of the top0.1% (i.e. above S999)"

*calculate the total wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen we_abv999_`s' = ts999_`s'*b_`s'*bracket999_`s'*0.001*total_taxunits
replace we_abv999_`s'=0 if we_abv999_`s'==.
}
gen we_abv999 =we_abv999_50+ we_abv999_100+ we_abv999_200+ we_abv999_500+ we_abv999_1000+ we_abv999_2000+ we_abv999_3000+ we_abv999_5000+ we_abv999_10000
label var we_abv999 "Total wealth of the top0.1% (i.e. above S999)"

*generate the beta coeffiecients for the top 0.1%
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen b999_`s' = b_`s'*bracket999_`s'
replace b999_`s'=0 if b999_`s'==.
}
gen b999 =b999_50+ b999_100+ b999_200+ b999_500+ b999_1000+ b999_2000+ b999_3000+ b999_5000+ b999_10000
label var b999 "beta-coefficient of the top0.1%"

* calculate the top0.1% wealth share
gen P999= we_abv999/w_total
label var P999 "Top 0.1% net wealth share on total net wealth"





   *    ** top 0.01% **    *
   
* create the absolute deviation from the 0.01%-population share for each wealth bracket _`s'
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen abs9999_`s'= abs(p_`s'- 0.0001)
}
 
* create an indicator (dummy) indicating the bracket where p_`s' is closest to 0.01% 
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen bracket9999_`s'=min(abs9999_50, abs9999_100, abs9999_200, abs9999_500, abs9999_1000, abs9999_2000, abs9999_3000, abs9999_5000, abs9999_10000)
replace bracket9999_`s' = 0 if bracket9999_`s' !=abs9999_`s'
replace bracket9999_`s' = 1 if bracket9999_`s'==abs9999_`s'
}

*drop the top0.01% absolute deviation variables
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
drop abs9999_`s'
}

*calculate the top0.01% wealth threshold ts9999:
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen ts9999_`s' = (k_`s'/0.0001^(1/a_`s'))*bracket9999_`s'
replace  ts9999_`s' = 0 if ts9999_`s'==.
}
gen ts9999 =  ts9999_50+ ts9999_100+ ts9999_200+ ts9999_500+ ts9999_1000+ ts9999_2000+ ts9999_3000+ ts9999_5000+ ts9999_10000
label var ts9999 "Net-Wealth threshold to belong to the top0.01%"

*calculate the average wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen we_avg9999_`s' = ts9999_`s'*b_`s'*bracket9999_`s'
replace we_avg9999_`s' = 0 if we_avg9999_`s'==.
}
gen we_avg9999 =we_avg9999_50+ we_avg9999_100+ we_avg9999_200+ we_avg9999_500+ we_avg9999_1000+ we_avg9999_2000+ we_avg9999_3000+ we_avg9999_5000+ we_avg9999_10000
label var we_avg9999 "Average net wealth of the top0.01% (i.e. above S9999)"

*calculate the total wealth above that threshold
foreach s in 50 100 200 500 1000 2000 3000 5000 10000 {
gen we_abv9999_`s' = ts9999_`s'*b_`s'*bracket9999_`s'*0.0001*total_taxunits
replace we_abv9999_`s'=0 if we_abv9999_`s'==.
}
gen we_abv9999 =we_abv9999_50+ we_abv9999_100+ we_abv9999_200+ we_abv9999_500+ we_abv9999_1000+ we_abv9999_2000+ we_abv9999_3000+ we_abv9999_5000+ we_abv9999_10000
label var we_abv9999 "Total wealth of the top0.01% (i.e. above S9999)"

*generate the beta coeffiecients for the top 0.01%
foreach s in 50 100 200 500 1000 2000 3000 5000 10000{
gen b9999_`s' = b_`s'*bracket9999_`s'
replace b9999_`s'=0 if b9999_`s'==.
}
gen b9999 =b9999_50+ b9999_100+ b9999_200+ b9999_500+ b9999_1000+ b9999_2000+ b9999_3000+ b9999_5000+ b9999_10000
label var b9999 "beta-coefficient of the top0.01%"

* calculate the top0.01% wealth share
gen P9999= we_abv9999/w_total
label var P9999 "Top 0.01% net wealth share on total net wealth"






*** *** *** *** *** *** *** 
* SHARES WITHIN SHARES *

gen top10_within_top1 =we_abv999/we_abv99
label var top10_within_top1 "Top 10% within the top 1% net wealth share"

gen top1_within_top1 =we_abv9999/we_abv99
label var top1_within_top1 "Top 1% within the top 1% net wealth share"

gen top10_within_top10 =we_abv99/we_abv90
label var top10_within_top10 "Top 10% within the top 10% net wealth share"



* top 10-5% shares
gen P10_5 = P90-P95
label var P10_5 "Top 10-5% net wealth share"

* top 5-1% shares
gen P5_1 = P95-P99
label var P5_1 "Top 5-1% net wealth share"

* top 10-1% shares
gen P10_1 = P90-P99
label var P10_1 "Top 10-1% net wealth share"


**** **** **** **** ****
* ALPHA AND BETA COEFFICIENTS 

gen alpha=1/(1-log(P99/P999)/log(10))
label var alpha "Pareto coefficient alpha"
note alpha: The Pareto-Lorenz a coefficients were computed using the top shares estimates. As a rule they were estimated from the top 0.1% share within the top 1% share: a=1/[1-log(Share1%/Share0.1%)/log(10)].

gen beta=alpha/(alpha-1)
label var beta "Inverted Pareto coefficient beta"
note beta: The inverted Pareto-Lorenz b coefficients were computed from the Pareto-Lorenz coefficients using the formula b=a/(a-1). Alternatively they can be computed by using directly the top wealth shares series and the formula: b=1/[log(Share1%/Share0.1%)/log(10)].

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*** *** *** *** *** *** *** 
* Average wealth per adult and per tax unit

gen avg_w_adult = w_total/total_adults
label var avg_w_adult "Average nominal net wealth per adult"
gen avg_w_taxunit = w_total/total_taxunits
label var avg_w_taxunit "Average nominal net wealth per tax unit"


*** *** *** *** *** *** *** 
* Express monetary variables in millions of CHF...
foreach n in 90 95 99 995 999 9999 {
replace we_abv`n'=we_abv`n'/1000000
}
replace w_total=w_total/1000000

* ... or in thousands of CHF
foreach n in 90 95 99 995 999 9999 {
replace ts`n'=ts`n'/1000
replace we_avg`n'=we_avg`n'/1000
}
replace avg_w_adult = avg_w_adult/1000
replace avg_w_taxunit = avg_w_taxunit/1000

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

keep cant year P90 P95 P99 P995 P999 P9999  P10_5 P5_1 P10_1 top10_within_top1 top1_within_top1 top10_within_top10 ///
we_avg90 we_avg95 we_avg99 we_avg995 we_avg999 we_avg9999 ///
ts90 ts95 ts99 ts995 ts999 ts9999 ///
we_abv90 we_abv95 we_abv99 we_abv995 we_abv999 we_abv9999 ///
total_taxunits tu_00 tu_total total_adults w_total avg_w_adult avg_w_taxunit ///
alpha beta 

order cant year P90 P95 P99 P995 P999 P9999  P10_5 P5_1 P10_1 top10_within_top1 top1_within_top1 top10_within_top10 ///
we_avg90 we_avg95 we_avg99 we_avg995 we_avg999 we_avg9999 ///
ts90 ts95 ts99 ts995 ts999 ts9999 ///
we_abv90 we_abv95 we_abv99 we_abv995 we_abv999 we_abv9999 ///
total_taxunits tu_00 tu_total total_adults w_total avg_w_adult avg_w_taxunit ///
alpha beta 

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 


* ADD THE EARLIER YEARS ESTIMATED BY DELL ET AL. 2007
append using "$thepath/6b_TopWealthShares_Dell_etal_1913-1997.dta"
// divide Dell et al.'s shares by 100
foreach var in  pct_covered positive_wealth_taxu P90 P95 P99 P995 P999 P9999  P10_5 P5_1 {
replace `var' = `var'/100 if year<=1997
}

replace pct_covered = 1 if year>2002
replace positive_wealth_taxu =  (tu_total-tu_00) /total_taxunits if year>2002

// update / add intermediate shares
replace P10_5 = P90-P95 
replace P5_1 = P95-P99
replace P10_1 = P90-P99

gen P05_01 = P995-P999
	label var P05_01 "Top 0.5-0.1% net wealth share"

gen P1_05 = P99-P995
	label var P1_05 "Top 1-0.5% net wealth share"

drop cant
compress
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
saveold "$thepath/7a_TopWealthShares_CH_1913-2011.dta", version(12) replace
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *








* CALCULATE TOP WEALTH SHARES CORRECTING FOR THE PENSION WEALTH */
// aws1_Pxxx: alternative wealth share correcting for the pension wealth in the denominator
// ass2_Pxxx: alternative wealth share correcting for the pension wealth in the denominator + adding average pension wealth p.c. to the top group pple
// ass3_Pxxx: alternative wealth share correcting for the pension wealth in the denominator + adding propoprtional pension wealth p.c. to the top group pple
// *proportional pension wealth: proportional to top labor income shares
// author: Isabel Martinez
// date: May 6 2016
// this version: July 2016


clear
cap clear matrix
cap log close
set more off
program drop _all


// get average share in labor incomes of each top group
use "$thepath/5b_TopLaborShares_1981-2010.dta", clear
keep if cat==3
keep cat year P90_ahv P95_ahv P99_ahv P995_ahv P999_ahv P9999_ahv
collapse P90_ahv P95_ahv P99_ahv P995_ahv P999_ahv P9999_ahv
tempfile z
save "`z'", replace
clear


// import pension-wealth statistics
import excel "$thepath/Data.xlsx", sheet(pk_wealth) cellrange(A1:D100) firstrow 
tempfile y
save "`y'", replace


// import top wealth shares and merge everything together
use "$thepath/7a_TopWealthShares_CH_1913-2011.dta", clear
merge 1:1 year using "`y'"
drop _merge

// add AVERAGE top labor shares
append using "`z'"
sort P90_ahv
foreach var in P90 P95 P99 P995 P999 P9999 {
	replace `var'_ahv=`var'_ahv[_n-1] if `var'_ahv==.
	label var `var'_ahv "Average labor income share of `var' of the labor income distribution 1981-2010"
}
sort year
drop if year==.

drop top10_within_top1 top1_within_top1 top10_within_top10 we_avg90 we_avg95 we_avg99 we_avg995 we_avg999 we_avg9999 ts90 ts95 ts99 ts995 ts999 ts9999 we_abv90 we_abv95 we_abv99 we_abv995 we_abv999 we_abv9999 alpha beta pk_snb pk_leimgruber

// interpolate missing pension wealth (assuming constant growth rate)
replace pk_wealth=log(pk_wealth)
ipolate pk_wealth year, gen(pk_wealth_i) epolate
replace pk_wealth_i=exp(pk_wealth_i)
replace pk_wealth=exp(pk_wealth)
	label var pk_wealth_i "pension wealth (in mio), interpolated"

// average pension wealth
gen double avg_pk=pk_wealth_i/total_taxunits
	label var avg_pk "average pension wealth p.c. (in mio CHF)"

// weight the pkw wealth with the tax units covered
gen double pk_wealth_iw=pk_wealth_i*pct_covered
	label var pk_wealth_iw "pension wealth (in mio), weighted by percent covered in tax statistics"

// generate a new denominator: wealth+pension wealth
gen double denom_w=w_total+ pk_wealth_iw
	label var denom_w "Total wealth denominator, incl. pension wealth (weighted by % covered in tax statistics)"

gen double denom=w_total+ pk_wealth_i
	label var denom "Total wealth denominator: taxable + pension wealth"

// label variables
label var positive_wealth_taxu 	"Tax returns with postive wealth (in % of total tax units, including non-filers)"
label var pct_covered			"Percent of wealth covered in wealth tax statistics"
label var total_taxunits		"Total tax units in the country"





* COMPUTE ALTERNATIVE WEALTH SHARES CORRECTING FOR PENSION WEALTH *

* alternative share 1: new denominator
// weighting for pension wealth 
foreach var in P90 P95 P99 P995 P999 P9999 {
gen aws1_`var' = (`var' * w_total)/denom_w
}
	// alternative share 1.1: withoutg weighting the pension wealth (for comparison only)
	foreach var in P90 P95 P99 P995 P999 P9999 {
	gen aws11_`var' = (`var' * w_total)/denom
	}

* alternative share 2: add average pension wealth 
local 90 = 0.9
local 95 = 0.95
local 99 = 0.99
local 995 = 0.995
local 999 = 0.999
local 9999 = 0.9999
foreach var in 90 95 99 995 999 9999 {
display 1- ``var'' 
gen N`var' = (1-``var'') * total_taxunits
replace N`var' = round(N`var' )
}

// top wealth share with denominator weigthed for percent not covered in tax statistics
//==> THIS IS THE VERSION WE USE IN THE PAPER
foreach var in 90 95 99 995 999 9999 {
gen  aws2_P`var' =(P`var' * w_total + avg_pk*N`var')/ denom_w 
}
	// top wealth share with unweigthed denominator
	foreach var in 90 95 99 995 999 9999 {
	gen  aws21_P`var' =(P`var'* w_total + avg_pk*N`var')/ denom 
	}


* alternative share 3: add proportional pension wealth to top group
// top wealth share with denominator weigthed for percent not covered in tax statistics
foreach var in 90 95 99 995 999 9999 {
gen aws3_P`var'=(P`var' * w_total + P`var'_ahv*pk_wealth_iw)/ denom_w 
}
	// top wealth share with unweigthed denominator
	foreach var in 90 95 99 995 999 9999 {
	gen aws31_P`var'=(P`var' * w_total + P`var'_ahv*pk_wealth_i)/ denom 
	}

order year P90 *_P90 P95 *_P95 P99 *_P99 P995 *_P995 P999 *_P999  P9999 *_P9999



replace avg_pk=avg_pk*1000
label var avg_pk "average pension wealth per family (in 1000 CHF)"
order year P90 aws2_P90 P95 aws2_P95 P99 aws2_P99 P995 aws2_P995 P999 aws2_P999  P9999 aws2_P9999 pk_wealth_iw avg_pk tu_total total_taxunits pct_covered positive_wealth_taxu w_total avg_w_taxunit

gen aws2_P10_5 = aws2_P90 - aws2_P95
gen aws3_P10_5 = aws3_P90 - aws3_P95

gen aws2_P5_1 = aws2_P95 - aws2_P99
gen aws3_P5_1 = aws3_P95 - aws3_P99

gen aws2_P1_05 = aws2_P99 - aws2_P995
gen aws3_P1_05 = aws3_P99 - aws3_P995

gen aws2_P05_01 = aws2_P995 - aws2_P999
gen aws3_P05_01 = aws3_P995 - aws3_P999


// gen difference between different methods
foreach group in P90 P95 P99 P995 P999 P9999 {
	gen diff1_`group' = aws2_`group' - aws1_`group'
	label var  diff1_`group' "difference in top shares adding avg. PK wealth vs. not adding avg. PK wealth to enumerator"
	gen diff2_`group' = aws3_`group' - aws2_`group'
	label var  diff2_`group' "difference in top shares adding proportional PK wealth vs. adding avg. PK wealth to enumerator"
}
// the difference between the weighted and unweighted computations is small (2% points for the top 10% group in the 1950s). We keep the the weighted estimates for consistency.

label var pk_wealth "Total pension wealth"

local 90 = 10
local 95 = 5
local 99 = 1
local 995 = 0.5
local 999 = 0.1
local 9999 = 0.01

foreach v in 90 95 99 995 999 9999 {
label var P`v' "Top ``v''% wealth share"
label var aws2_P`v' "Top ``v''%, incl. pension wealth (avg.)"
label var aws3_P`v' "Top ``v''%, incl. pension wealth (prop.)"
}

order year P90 aws2_P90 aws3_P90 P95 aws2_P95 aws3_P95 P99 aws2_P99 aws3_P99 P995 aws2_P995 aws3_P995 P999 aws2_P999 aws3_P999  P9999 aws2_P9999 aws3_P9999 ///
pk_wealth pk_wealth_i pk_wealth_iw avg_pk tu_total total_taxunits pct_covered positive_wealth_taxu w_total avg_w_taxunit ///
P90_ahv P95_ahv P99_ahv P995_ahv P999_ahv P9999_ahv

// save a data set with results
keep year P90 aws2_P90 aws3_P90 P95 aws2_P95 aws3_P95 P99 aws2_P99 aws3_P99 P995 aws2_P995 aws3_P995 P999 aws2_P999 aws3_P999  P9999 aws2_P9999 aws3_P9999 ///
pk_wealth pk_wealth_i pk_wealth_iw avg_pk tu_total  total_taxunits pct_covered positive_wealth_taxu w_total avg_w_taxunit ///
P90_ahv P95_ahv P99_ahv P995_ahv P999_ahv P9999_ahv

compress
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
saveold "$thepath/7b_TopWealthShares_CH_1913-2011-corrected.dta", version(12) replace
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

